package com.yoku.user.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dubbo.annotation.Provider;
import com.google.common.collect.Maps;
import com.google.common.eventbus.EventBus;
import com.yoku.mybatis.model.PageData;
import com.yoku.mybatis.model.Result;
import com.yoku.user.dao.UserDao;
import com.yoku.user.model.Shop;
import com.yoku.user.model.User;
import com.yoku.user.search.Esearch;
import com.yoku.user.service.UserReadService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * Desc:
 * Author:
 * Date: 2016/12/5
 */
@Provider
@Service
public class UserReadServiceImpl implements UserReadService {

    @Autowired
    private UserDao userDao;

    @Autowired
    private Esearch esearch;

    @Autowired
    private EventBus eventBus;

    @PostConstruct
    public void init(){
        eventBus.post(new Object());
    }

    @Override
    public Result<User> login(String username, String password) {
        Result<User> userResult = new Result();
        userDao.findByParam();
        return userResult;
    }

    @Override
    public Boolean create(User user) {
        userDao.create(user);
        esearch.indexUser(user);
        esearch.indexShop(new Shop());
        return true;
    }

    @Override
    public PageData<User> page(Integer pageNO, Integer pageSize, Map<String, Object> param) {
        Map<String, Object> data = Maps.newHashMap();
        PageData<User> userPageData = userDao.page(pageNO, pageSize, param);
        return userPageData;
    }
}
